<template>
  <div class="goods-item clear">
    <img v-lazy="showImage" @load="imgLoad" @click="imgDetail">
    <div class="goods-info">
      <p>{{goodsItem.title}}</p>
      <span class="price">{{goodsItem.price}}</span>
      <el-button class="colIcon" type="warning" icon="el-icon-star-off" circle :class="{active:active}" @click="goodsCollet"></el-button>
      <span class="collet">{{goodsItem.cfav}}</span>
    </div>
  </div>
</template>

<script>
  export default {
    name: "GoodsListItem",
    data(){
      return {
        active:false
      }
    },
    props:{
      goodsItem:{
        type:Object
      }
    },
    computed:{
      showImage(){
        return this.goodsItem.image || this.goodsItem.show.img
      }
    },
    methods:{
      goodsCollet(){
        this.active=!this.active;
      },
      imgLoad(){
        this.$bus.$emit('imgLoad');
      },
      // 跳转到商品详情页
      imgDetail(){
        this.$router.push('/detail/'+this.goodsItem.iid);
      }
    }
  }
</script>

<style scoped>

  .goods-item {
    /*float: left;*/
    width:50%;
    padding-left: 5px;
    padding-right: 5px;
    margin-bottom: 5px;
  }
  .goods-item img {
    width: 100%;
    border-radius: 5px;
  }
  .goods-info {
    font-size: 12px;
    text-align: center;
    overflow: hidden;
  }
  .goods-info p {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    margin-bottom: 3px;
  }
  .goods-info .price {
    color: var(--color-high-text);
    margin-right: 20px;
  }

  .colIcon {
    padding: 3px;
    background-color: #f7f7f7;
    color: #ff5777;
    margin-right: 6px;
  }
  .active {
    background-color: #ff5777;
    color: #f7f7f7;
  }
</style>
